home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue54 / Persist / FEditAddress.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-01-21  |  2.7 KB  |  98 lines

  1. {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2.   (c) TechInsite Pty. Ltd.
  3.   PO Box 429, Abbotsford, Melbourne. 3067 Australia
  4.   Phone: +61 3 9419 6456
  5.   Fax:   +61 3 9419 1682
  6.   Web:   www.techinsite.com.au
  7.   EMail: peter_hinrichsen@techinsite.com.au
  8.  
  9.   Created: Jan 2000
  10.  
  11.   Notes: Popup dialog for editing an address
  12.  
  13. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  14. unit FEditAddress;
  15.  
  16. interface
  17.  
  18. uses
  19.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  20.   ExtCtrls, tiButtonPanel, Adrs_BOM, StdCtrls
  21.   ;
  22.  
  23. type
  24.   TFormEditAddress = class(TForm)
  25.     tiButtonPanel1: TtiButtonPanel;
  26.     cbAddressType: TComboBox;
  27.     eCountry: TEdit;
  28.     mAddress: TMemo;
  29.     eState: TEdit;
  30.     ePostCode: TEdit;
  31.     Label1: TLabel;
  32.     Label2: TLabel;
  33.     Label3: TLabel;
  34.     Label4: TLabel;
  35.     Label5: TLabel;
  36.     procedure tiButtonPanel1Btn1Click(Sender: TObject);
  37.     procedure tiButtonPanel1Btn2Click(Sender: TObject);
  38.   private
  39.     FData: TAddress;
  40.     procedure SetData(const Value: TAddress);
  41.   public
  42.     property Data : TAddress read FData write SetData ;
  43.   end;
  44.  
  45. implementation
  46.  
  47. {$R *.DFM}
  48.  
  49. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  50. // *
  51. // * TFormEditAddress
  52. // *
  53. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  54. procedure TFormEditAddress.SetData(const Value: TAddress);
  55. begin
  56.  
  57.   FData := Value;
  58.   cbAddressType.ItemIndex := cbAddressType.Items.IndexOf( FData.AdrsType ) ;
  59.   mAddress.Lines.Text     := FData.Lines ;
  60.  
  61.   eState.Text             := FData.State ;
  62.   ePostCode.Text          := FData.PCode ;
  63.   eCountry.Text           := FData.Country ;
  64.  
  65. end;
  66.  
  67. // The OK button on click event
  68. //------------------------------------------------------------------------------
  69. procedure TFormEditAddress.tiButtonPanel1Btn1Click(Sender: TObject);
  70. begin
  71.   if cbAddressType.ItemIndex = -1 then begin
  72.     cbAddressType.SetFocus ;
  73.     raise exception.Create( 'Please select an address type.' ) ;
  74.   end ;
  75.  
  76.   if mAddress.Lines.Text = '' then begin
  77.     mAddress.SetFocus ;
  78.     raise exception.Create( 'Please enter an address.' ) ;
  79.   end ;
  80.  
  81.   FData.AdrsType := cbAddressType.Items[ cbAddressType.ItemIndex ] ;
  82.   FData.Lines    := mAddress.Lines.Text ;
  83.   FData.State    := eState.Text         ;
  84.   FData.PCode    := ePostCode.Text      ;
  85.   FData.Country  := eCountry.Text       ;
  86.   ModalResult    := mrOK ;
  87.  
  88. end;
  89.  
  90. // Cancel button on click event
  91. //------------------------------------------------------------------------------
  92. procedure TFormEditAddress.tiButtonPanel1Btn2Click(Sender: TObject);
  93. begin
  94.   ModalResult := mrCancel ;
  95. end;
  96.  
  97. end.
  98.